package common

import (
	"log/slog"
	"time"
)

var (
	// 重试等待时间
	sleepTimes = []time.Duration{time.Minute, 2 * time.Minute, 5 * time.Minute, 10 * time.Minute}
	SleepIndex = 0
)

func WaitSleep(name string, waitTime time.Duration) {
	if waitTime > 0 {
		slog.Info("waitSleep", "waitName", name, "sleep", waitTime)
		time.Sleep(waitTime)
	} else {
		sleepTime := sleepTimes[SleepIndex]
		slog.Info("waitSleep", "waitName", name, "sleep", sleepTime)
		// 等待一段时间，等待时间递增，且不超过maxTimeSleep
		time.Sleep(sleepTime)
		SleepIndex++
		if SleepIndex >= len(sleepTimes)-1 {
			SleepIndex = len(sleepTimes) - 1
		}
	}
}
